//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef _BL_BUART_H
#define _BL_BUART_H

//??#ident "$Id: buart.h,v 1.1.2.1 2006/10/10 10:30:48 zhangyi Exp $"

#include "types.h"
#include "bulverde.h"

#define BTRBR __REG(BTUART_BASE_PHYSICAL+BT_RBR_OFFSET)
#define BTTHR __REG(BTUART_BASE_PHYSICAL+BT_THR_OFFSET)
#define BTIER __REG(BTUART_BASE_PHYSICAL+BT_IER_OFFSET)
#define BTIIR __REG(BTUART_BASE_PHYSICAL+BT_IIR_OFFSET)
#define BTFCR __REG(BTUART_BASE_PHYSICAL+BT_FCR_OFFSET)
#define BTLCR __REG(BTUART_BASE_PHYSICAL+BT_LCR_OFFSET)
#define BTMCR __REG(BTUART_BASE_PHYSICAL+BT_MCR_OFFSET)
#define BTLSR __REG(BTUART_BASE_PHYSICAL+BT_LSR_OFFSET)
#define BTMSR __REG(BTUART_BASE_PHYSICAL+BT_MSR_OFFSET)
#define BTSPR __REG(BTUART_BASE_PHYSICAL+BT_SPR_OFFSET)
#define BTDLL __REG(BTUART_BASE_PHYSICAL+BT_DLL_OFFSET)
#define BTDLH __REG(BTUART_BASE_PHYSICAL+BT_DLH_OFFSET)
#define BTISR __REG(BTUART_BASE_PHYSICAL+BT_ISR_OFFSET)
#define BTFOR __REG(BTUART_BASE_PHYSICAL+BT_FOR_OFFSET)
#define BTABR __REG(BTUART_BASE_PHYSICAL+BT_ABR_OFFSET)
#define BTACR __REG(BTUART_BASE_PHYSICAL+BT_ACR_OFFSET)

typedef enum { /* Some useful SA-1100 baud rates */
    baud1k2 = 192,
    baud9k6 = 96,
    baud19k2 = 48,
    baud38k4 = 24,
    baud57k6 = 16,
    baud115k2 = 8
} eBauds;

/* Function protos */
void buart_init(eBauds baudrate);

void buart_output_byte(const char c);
void buart_output_rawbyte(const char c);
void buart_output_string(const char *s);
void buart_output_hex(const u32 h);
void buart_output_byteinhex(const char c);
void buart_output_dec(const u32 d);
void buart_output_block(const char *buf, int bufsize);

int  buart_input_byte(char *c);
int  buart_input_str(char *buf, int count);
int  buart_input_string(char *s, const int len, const int timeout);
int  buart_input_block(char *buf, int bufsize, const int timeout);
void  buart_input_flush(void);

int buart_clear_rx(void);
#if 0//DEBUG
#define Debug_outputString(x) buart_output_string(x)
#define Debug_outputByte(x) buart_output_byte(x)
#define Debug_outputHex(x) buart_output_hex(x)
#define Debug_outputByteInHex(x) buart_output_byteinhex(x)
#define Debug_outputDec(x) buart_output_dec(x)
//#else
#define Debug_outputString(x)
#define Debug_outputByte(x)
#define Debug_outputHex(x)
#define Debug_outputByteInHex(x)
#define Debug_outputDec(x)
#endif

#endif
